package com.coordinate.core.message.impl;

import java.util.LinkedList;
import java.util.List;

import com.coordinate.core.transport.Email;
import com.coordinate.core.transport.Sms;
import com.coordinate.core.transport.VoiceCall;
import com.coordinate.core.type.LangText;
import com.google.appengine.api.datastore.Blob;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.Key;

import javax.jdo.annotations.*;

@PersistenceCapable
public class CVoiceMessage extends CMessage
implements Sms,VoiceCall,Email
{
  
    @Persistent 
    private String mFileName;
    
    @Persistent(defaultFetchGroup="true")
    private Blob        mVmFile;
    
    @Persistent
    private String mContentType;
    
    public CVoiceMessage()
    {
       	this.mVmFile = null;
       	this.mKey = null;
    }
    
    public CVoiceMessage(Blob pBlob,String pFileName)
    {
       	this.mVmFile = pBlob;
       	this.setFileName(pFileName);
    }
    
       
	public String getFileName() {
		return mFileName;
	}

	public void setFileName(String pFileName) {
		this.mFileName = pFileName;
	}

	public String getContentType() {
		return mContentType;
	}

	public void setContentType(String pContentType) {
		this.mContentType = pContentType;
	}

	public Blob getVmFile() {
		return mVmFile;
	}

	public void
    setVm(Blob pVmFile)
    {
    	this.mVmFile = pVmFile;
    }
	
	public Blob
    getVm()
    {
    	return this.mVmFile;
    }
    
    public String  getVmKey()
    {
       return KeyFactory.keyToString(this.mKey);	
    }

	public String getSmsBody(String pLangCode) {
		
		String lSmsBody = null;
		
		if(this.getFileName().endsWith("mp3"))
		{
			lSmsBody = "http://egov-innovations.appspot.com/GetVm.mp3?vm_key="+this.getEmailKey();
		}
		else
		{
			lSmsBody = "http://egov-innovations.appspot.com/GetVm.wav?vm_key="+this.getEmailKey();
		}
		return " Hello, You have a new Voice Message, " + lSmsBody;
		
	}

	public String getSmsFrom() {
		// TODO Auto-generated method stub
		return "3700";
	}

	public String getSmsKey() {
		// TODO Auto-generated method stub
		return KeyFactory.keyToString(this.mKey);
	}


	public List getSmsReceipientsList() {
		/** Get the Resolver from Amith and send the list**/
		List lList = new LinkedList();
		lList.add("971501325042");
		lList.add("971559266628");
		lList.add("971506211757");
		return lList;
	}


	public String getSmsSubjectLine() {
		
		if(null == this.mSubject)
			return "You have a new Voice message";
		return this.mSubject;
	}

	public List<String> getPhoneNumbers() {
		List lList = new LinkedList();
		lList.add("971501325042");
		lList.add("971559266628");
		lList.add("971506211757");
		return lList;
	}

	public String getVoiceMessage() {
		// TODO Auto-generated method stub
		return null;
	}

	public String getVoiceMessageKey() {
		// TODO Auto-generated method stub
		return KeyFactory.keyToString(this.mKey);
	}

	public String getEmailBody() {
		String lEmailBodyHeader = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
		String lHtmlStartTag = "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
		String lHtmlEndTag ="</html>";
		String lBodyStartTag="<body bgcolor=\"ivory\">";
		String lBodyEndTag="</body>";
		
		String lEmailBody = lEmailBodyHeader + lHtmlStartTag+ lBodyStartTag;
		lEmailBody = lEmailBody +  "<div align=left><img src=\"http://egov-innovations.appspot.com/logo_govt.jpg\"></div>";
		
		lEmailBody = lEmailBody + "<table align=center cellspacing=20>";
		if(this.getFileName().endsWith("mp3"))
		{
			lEmailBody = lEmailBody + "<tr><td>" + "<a href=http://egov-innovations.appspot.com/GetVm.mp3?vm_key="+this.getEmailKey()+" >To Listen to Your new Voice Message, please click here and download the voice message.</a>" +"</td></tr>";
		}
		else
		{
		lEmailBody = lEmailBody + "<tr><td>" + "<a href=http://egov-innovations.appspot.com/GetVm.wav?vm_key="+this.getEmailKey()+" >To Listen to Your new Voice Message, please click here and download the voice message.</a>" +"</td></tr>";
		}
		
		lEmailBody = lEmailBody + "</table></body></html>";
		
		return lEmailBody;
	}

	public List<String> getEmailCCList() {
		// TODO Auto-generated method stub
		return null;
	}

	public String getEmailFrom() {
		// TODO Auto-generated method stub
		return "simithn@gmail.com";
	}

	public String getEmailKey() {
		// TODO Auto-generated method stub
		return KeyFactory.keyToString(this.mKey);
	}

	public List getEmailReceipientsList() {
		 List<String> lList = new LinkedList<String>();
			
			//lList.add("simith@ctg.ae");
			lList.add("simithn@yahoo.com");
			lList.add("simithn@gmail.com");
			lList.add("watchersparadise@gmail.com");
			lList.add("amithmit@yahoo.com");
			return lList;
		
	}

	public String getEmailSubjectLine() {
		if(null == this.mSubject)
			return "You have a new Voice message";
		return this.mSubject;
		
	}

	public List<String> getEmailToList() {
		 List<String> lList = new LinkedList<String>();
			
			
			lList.add("simithn@yahoo.com");
			lList.add("simithn@gmail.com");
			lList.add("watchersparadise@gmail.com");
			lList.add("amithmit@yahoo.com");
			return lList;
		
	}
   
    
}
